package com.easyfun.healthmagicbox.comm.json;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;


import com.easyfun.healthmagicbox.pojo.HeartBeatMessage;

public class ServerHeartBeatListJsonWrapper <T extends JsonWrapper> 
	extends AbstractListJsonWrapper<T, HeartBeatMessage>{
		public ServerHeartBeatListJsonWrapper()
		{
			super();
		}
		public ServerHeartBeatListJsonWrapper(List<HeartBeatMessage> pps) {
			super(pps);
		}

		
		public void deserializeFromObj(JSONObject obj) throws JSONException {
		
			ServerHeartBeatJsonWrapper<?,?> leafwrapper;
				try {
					leafwrapper = ServerHeartBeatJsonWrapper.getInstance(
							obj, 
							ServerHeartBeatJsonWrapper.class);

					mpps.add(leafwrapper.getDataPojo());
				} catch (InstantiationException e) {
					e.printStackTrace();
					throw new JSONException(e.toString());
				} catch (IllegalAccessException e) {
					e.printStackTrace();
					throw new JSONException(e.toString());
				}

		}


		public JSONObject serializeToObj() throws JSONException {
			JSONObject serializedObj = new JSONObject();

			int i = 0;
			for (HeartBeatMessage pp : mpps) {
				ServerHeartBeatJsonWrapper<?,?> leafwrapper = new ServerHeartBeatJsonWrapper(
						pp);
				serializedObj.put(String.valueOf(i), leafwrapper.serialize());
				i++;
			}

			return serializedObj;
		}

	}
